#pragma once



#include "shared\shared.h"
#include "graphics.h"

#define GRABBER_SIZE 6

namespace vgl{

enum shape_type_t{
	shape_rectangle,
	shape_ecclipse,
	shape_five_corner_star,
	shape_annotation1,
	shape_annotation2,
};

enum ctrl_point_type_t{
	ctrl_resize,  //resize
	ctrl_distort,
	ctrl_rotate,
};


struct ctrl_point_t{
	ctrl_point_type_t ctl_type;
	point_t  ctrl_point;
};



//a stencil is a type-ctrl-point-set binding
struct stencil_t{
	//shape_type_t shape_type;
	std::vector<ctrl_point_t *> ctrl_pts;

	stencil_t(){};
	~stencil_t(){
		delete_vector(ctrl_pts);
	};

	void add_ctrl_point(ctrl_point_type_t t,point_t &pt){
		ctrl_point_t  * cts = new ctrl_point_t();
		cts->ctl_type = t;
		cts->ctrl_point = pt;

		ctrl_pts.push_back(cts);
	};
};


class Shape{
private:
protected:
	shape_type_t m_type;

	//transform that used from standard space to current graphics coordinate space.
	//after each transform ,this was accumulated and used to compute the real position
	//of each control points
	matrix_t m_transform;

	//real control points
	std::vector<point_t> m_ctrl_pts;

public:
	Shape(shape_type_t t);
	~Shape();


	void add_control_point(int x,int y){
		m_ctrl_pts.push_back(point_t(x,y));
	}

	virtual void draw(graphics_t & g) ;

	//draw all control points,after the shape-rendering finished
	void draw_control_points(graphics_t &g);

	void get_bbox(rect_t & rc);

	//test if hit test the polygon
	bool hit_test(point_t &pt,int n);

	//test if hit any ctrl point,return the index of the control points
	//return 0 if not hit,index start from 1
	int hit_ctrl(point_t &pt);
};


};
